package com.youzi.tunnel.server.entity;


import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author youzi
 * @since 2023-04-08
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class Tunnel implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id")
    private String id;

    /* 隧道名称 */
    private String name;

    /* 源端口 */
    private Integer fromPort;
    /* 源主机 */
    private String fromHost;
    /* 源端口 */
    private String fromClient;
    /* 到端口 */
    private Integer toPort;
    /* 到客户端 */
    private String toClient;

    /* 状态：1开启，0关闭 */
    private Integer state;

    /* 服务端绑定链路时用于临时记录channel的Id */
    @TableField(exist = false)
    private String channelId;

    //开启状态,1开启成功,0开启失败
    @TableField(exist = false)
    private Integer fromState;
    //开启状态,1开启成功,0开启失败
    @TableField(exist = false)
    private Integer toState;

    @TableField(exist = false)
    private boolean isAlive;   //是否存活

    public Tunnel() {
    }

    public Tunnel(String id, String name, Integer fromPort, String fromHost, String fromClient, Integer toPort, String toHost, String toClient, Integer state) {
        this.id = id;
        this.name = name;
        this.fromPort = fromPort;
        this.fromHost = fromHost;
        this.fromClient = fromClient;
        this.toPort = toPort;
        this.toClient = toClient;
        this.state = state;
    }

    public Tunnel copy() {
        Tunnel tunnel = new Tunnel();
        tunnel.setId(id);
        tunnel.setName(name);
        tunnel.setFromPort(fromPort);
        tunnel.setFromHost(fromHost);
        tunnel.setFromClient(fromClient);
        tunnel.setToPort(toPort);
        tunnel.setToClient(toClient);
        return tunnel;
    }
}
